<?php
//include the functions.php
require "include/functions.php";
//check_session();

/*
	Generates the quiry data for current stock level
	Created by		 : Lee
	Created On		 : 29.August.2011
	Last Modification: created document
	Modified On		 : 29.August.2011
	Modified By		 : Lee
*/

// Define Data Variables
$userName = "";
$orderNumber ="";
$productId ="";

// Requestings inputs from the form to php variables

if(!filter_has_var(INPUT_POST, "product_id")){}
else
	{
		$productId = $_REQUEST["product_id"];
	}
if(!filter_has_var(INPUT_POST, "order_number")){}
else
	{
		$orderNumber = $_REQUEST["order_number"];
	}
if(!filter_has_var(INPUT_POST, "user_name")){}
else
	{
		$userName = $_REQUEST["user_name"];
	}
?>

<html>
<head>
<title>Home Electronics - User Historical Purchases</title>
<link rel="stylesheet" href="include/styles.css" type="text/css">
<script src="include/functions.js"></script>
<script>window.onload=function(){
	altRows('alternatecolor');
}</script>
</head>
<body>
<div id="container" align="center">
  
	<div id="body" align="center">
		<div>
 <h1>Historical Purchases</h1> 
			<fieldset style="width:94%; text-align:center">
            <legend>Search Criteria</legend>
            <form name="form1" action="user_historical_purchases.php" method="post">
            <table style="margin-right:7%">
            	<tr>
                    <td>ProductID</td><td><input name='product_id' value='<?=$productId?>'/></td>
					<td>OrderID</td><td><input name='order_number' value='<?=$orderNumber?>'/></td>
					<td>Customer</td><td><input name='user_name' value='<?=$userName?>'/></td>
					<td><input type="submit" name="Search"></td>
                </tr>
            </table>
            </form>
            </fieldset>

		    <?php
			$table = ("product_customer_order pco, user u");
			$table_rows= array ("pco.product_id","pco.order_number","u.user_name","pco.order_quantity","pco.quantity_sent","pco.unit_cost");
			$condition = ("(product_id like '$productId%' or product_id='') and (order_number like '$orderNumber%' or order_number='')");
		
			echo("<table class='altrowstable' id='alternatecolor'><tr><th width='10%'>ProductID</th><th width='10%'>OrderID</th><th>Customer Name</th><th>Order Quantity</th><th>Quantity Sent</th><th>Unit Cost</th></tr>");
			$result = query_table("home_electronics","home","home_e",$table,$table_rows,$condition, false, false);
			echo($result."<table></a>");
			?>

		
		</div>  
	</div> <!--body div -->
   		
</div>
</body>
</html>